package servicesImp.business;

import base.IBaseMapperWithoutBLOBs;
import base.IBaseServicesWithoutBLOBsImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import services.business.BusinessInfoServices;
import services.business.InspectorInfoServices;
import wt.dao.business.InspectorInfoMapper;
import wt.entity.business.BusinessInfo;
import wt.entity.business.InspectorInfo;
import wt.entity.business.InspectorInfoExample;
import wt.staticData.ShortData;
import wt.staticData.TableName;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/10/14.
 */
@Service
public class InspectorInfoServicesImp extends IBaseServicesWithoutBLOBsImpl< InspectorInfo, InspectorInfoExample> implements InspectorInfoServices {
    @Autowired
    InspectorInfoMapper inspectorInfoMapper;
    @Autowired
    BusinessInfoServices businessInfoServices;

    @Override
    public IBaseMapperWithoutBLOBs< InspectorInfo, InspectorInfoExample> getMapper() {
        return this.inspectorInfoMapper;
    }

    @Override
    public String getTableName() {
        return TableName.BUS_INSPECTOR_INFO;
    }


    @Transactional
    public void insertSelective(List<InspectorInfo> inspectorInfoList, String businessId, Date startTime, Date endTime) throws Exception {
        BusinessInfo businessInfo = new BusinessInfo();
        businessInfo.setId(businessId);
        businessInfo.setBusinessWorkFlow(ShortData.s2);
        businessInfo.setInspectorCount(inspectorInfoList.size());
        businessInfo.setArrangeStartTime(startTime);
        businessInfo.setArrangeEndTime(endTime);
        businessInfoServices.updateByPrimaryKeySelective(businessInfo);
        for (InspectorInfo inspectorInfo : inspectorInfoList) {
            inspectorInfo.setBusinessId(businessId);
            getCurrentProxy().insertSelective(inspectorInfo);
        }
    }


    public List<InspectorInfo> selectByBusinessId(String businessId) throws Exception {
        InspectorInfoExample inspectorInfoExample = new InspectorInfoExample();
        inspectorInfoExample.createCriteria().andBusinessIdEqualTo(businessId);
        return selectByExample(inspectorInfoExample);

    }

    public List<InspectorInfo> selectByExpertId(String expertId) throws Exception {
        InspectorInfoExample inspectorInfoExample = new InspectorInfoExample();
        inspectorInfoExample.createCriteria().andExpertIdEqualTo(expertId);
        return selectByExample(inspectorInfoExample);
    }
}
